<template>
  <el-dialog title="编辑" :model-value="popShow" width="30%" center :show-close="false">
    <el-form :model="editData" ref="ruleFormRef">
      <el-form-item label="课程标题" prop="title" required>
        <el-input v-model="editData.title" placeholder="请输入标题"></el-input>
      </el-form-item>
      <el-form-item label="课程价格" prop="price" required>
        <el-input v-model="editData.price" placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="confirmClick('cancel')">取消</el-button>
        <el-button type="primary" @click="submitForm(ruleFormRef)">确认</el-button>

      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script setup>
import {defineProps,reactive} from 'vue';

/**
 * 编辑弹窗
 */
const {popShow,message,confirmClick} =defineProps(['popShow','message','confirmClick'])
const editData = reactive({
  title:message.title,
  price:message.price,
  id:message.id
})

/**
 * 表单的校验
 */
const ruleFormRef=ref(null)
const submitForm=async(formEL)=>{
  if (!formEL) return
  await formEL.validate((valid,fields)=>{
    if (valid){
      confirmClick({
        title: editData.title,
        price: editData.price,
        id:editData.id
      })
    }else {
      console.log("错误信息",fields)
    }
  })
}


</script>

<style lang='less' scoped>
.dialog-footer button:first-child {
  margin-right: 10px;
}

:deep(.el-form-item__label) {
  width: 80px !important;
}

:deep(.el-form-item__content) {
  justify-content: center;
  margin-left: 0 !important;
}
</style>